package qf.module.redis.controller;

import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import qf.common.core.web.vo.AjaxResult;
import qf.common.redis.utils.RedisUtil;

import javax.annotation.Resource;

@RestController
@RequestMapping("redis/api")
@RefreshScope // 解决nacos修改配置不实时生效问题
public class RedisController {

    @Resource
    private RedisUtil redisUtil;

    @RequestMapping(value = "/v1/test")
    public AjaxResult LuckyTest(@RequestParam(value = "key") String key) {

        Object value = redisUtil.get(key);
        if (value == null) {
            System.out.println("当前不存在相关缓存对象，进行赋值操作");
            redisUtil.set(key,System.currentTimeMillis() + "",10);
            System.out.println("赋值成功，当前参数：" + redisUtil.get(key));
        } else {
            System.out.println("存在缓存对象，值：" + redisUtil.get(key));
        }
        return AjaxResult.success(redisUtil.get(key));
    }
}
